import { login } from "../../utils/asyncWx.js"
import { request } from "../../request/index.js"
// pages/auth/auth.js
Page({

  data: {

  },
  async handleGetUserInfo(e) {

    try {
      const { rawData, signature, encryptedData, iv } = e.detail
      const { code } = await login()
      const loginParams = { rawData, signature, encryptedData, iv, code }
      //请求
      const { token } = await request({ url: "/users/wxlogin", data: loginParams, methods: "post" })
      //存入缓存
      // wx.setStorageSync("token", token);  //评论区的token
      wx.setStorageSync("token", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo");
      //返回上一层
      wx.navigateBack({
        delta: 1 //1就是返回上一层
      });
    } catch (error) {
      console.log(error);
    }

  },
  onLoad: function (options) {

  },
})